class PaymentMethodsController < ApplicationController
  before_action :set_menu

  def index
    @submenu = :payment_method
    @title = '付款方式'
    @payment_methods = PaymentMethod.all
  end

  def new
    @payment_method = PaymentMethod.new
  end

  def create
    @payment_method = PaymentMethod.new post_params
    if @payment_method.save
      redirect_to payment_methods_path
    else
      render :action => 'new'
    end
  end

  def edit
    @payment_method = PaymentMethod.find params[:id]
  end

  def update
    @payment_method = PaymentMethod.find params[:id]
    if @payment_method.update_attributes post_params
      redirect_to payment_methods_path
    else
      render :action => 'edit'
    end
  end

  def destroy
    @payment_method = PaymentMethod.find params[:id]
    @payment_method.destroy
    redirect_to payment_methods_path
  end


  def post_params
    params.require(:payment_method).permit(*%w(name))
  end

  private
  def set_menu
    @mainmenu = :base_data
  end
end
